package com.qianya.system.face.config;


import com.qianya.system.face.web.patient.model.PatientFileInfo;
import com.qianya.system.face.web.patient.service.IPatientFileInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

@Component
@Slf4j
public class ProjecStartUpConfig implements ApplicationRunner {
    @Autowired
    private IPatientFileInfoService fileInfoService;
    /**
     * @desc  启动注册项
     * @author lhl
     * @date 2020-07-01 15:51
     * @return
    */
    @Override
    public void run(ApplicationArguments args) throws Exception {
         Object object=RedisUtil.hget("fileInfo","");
         if (object!=null){
            Map<String,Object> map=(Map<String,Object>)object;
            if (map.size()==0){
                List<PatientFileInfo> list=fileInfoService.list();
                for (int i = 0; i <list.size() ; i++) {
                    map.put(list.get(i).getFileId(),list.get(i));
                }
                if (map.size()!=0){
                    RedisUtil.hset("fileInfo",map);
                    log.info("人脸库初始化成功--");
                }
            }
        }

    }
}
